package cn.myjerry.server.demo1;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class Server2 {
	private ServerSocket server;
	
	public static void main(String[] args) {
		Server2 server = new Server2();
		server.start();
	}
	
	public void start() {
		try {
			server = new ServerSocket(8888);
			
			this.receive();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	private void receive() {
		try {
			Socket client = server.accept();
			
			StringBuffer sb = new StringBuffer();
			String msg = null;
			
			BufferedReader br = new BufferedReader(new InputStreamReader(client.getInputStream()));
			
			while((msg=br.readLine()).length() > 0) {
				
				sb.append(msg);
				sb.append("\r\n");
				if(null == msg) {
					break;
				}
			}
			
			String requestInfo = sb.toString().trim();
			
			System.out.println(requestInfo);
			
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public void stop() {
		
	}
}
